<template>
  <div>
    <avue-crud
      :page="page"
      :data="dataList"
      :option="tableOption"
      :table-loading="dataListLoading"
      @on-load="getDataList"
      @search-change="searchChange"
    >
      <template slot-scope="scope"
                slot="status">
        <el-tag v-if="scope.row.status === 0"
                size="small" type="warning">待审核</el-tag>
        <el-tag v-else-if="scope.row.status === 1"
                size="small" type="success">审核通过</el-tag>
        <el-tag v-else
                size="small" type="danger">拒绝</el-tag>
      </template>
      <template slot-scope="scope"
                slot="menu">
        <el-row v-if="scope.row.status === 0">
          <el-button type="primary"
                     size="small"
                     @click="audit(scope.row.id,1)">审核通过</el-button>
          <el-button type="danger"
                     size="small"
                     @click="audit(scope.row.id,2)">不通过</el-button>
        </el-row>
        <el-row v-else-if="scope.row.status === 2">
          <el-button type="primary"
                     size="small"
                     @click="audit(scope.row.id,1)">审核通过</el-button>
        </el-row>


      </template>
    </avue-crud>
  </div>
</template>

<script>
  import { tableOption } from '../../../crud/distribution/pickMoney'

  export default {
    name: 'distributionPickMoneyList',
    data () {
      return {
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        },
        dataListLoading: false,
        dataList: [],
        tableOption: tableOption
      }
    },
    methods: {
      getDataList: function (page, params) {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/distributor/cash/withdrawal/list'),
          method: 'get',
          params: this.$http.adornParams(
            Object.assign(
              {
                current: page == null ? this.page.currentPage : page.currentPage,
                size: page == null ? this.page.pageSize : page.pageSize
              },
              params
            )
          )
        }).then(({ data }) => {
          console.log(data)
          this.dataList = data.records
          this.dataListLoading = false
          this.page.total = data.total
        })
      },
      searchChange: function (params, done) {
        this.getDataList(this.page, params)
        done()
      },

      selectionChange: function () {

      },

      // 审核
      audit: function (id, status) {
        this.$confirm(`确定进行[${status === 1 ? '审核通过' : '拒绝'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.dataListLoading = true
          let params = {'id': id, 'status': status}
          this.$http({
            url: this.$http.adornUrl('/distributor/cash/withdrawal'),
            method: 'POST',
            params: this.$http.adornParams(
              params
            )
          }).then(({ data }) => {
            this.dataListLoading = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList(this.page)
              }
            })
          })
        }).catch(() => { })
      }
    }
  }
</script>

<style scoped>

</style>
